#include "sys.h"

bit flag200ms,flag300ms;
bit flag800ms,flag400ms;

u8 Max=0,Min=1;
u8 tempMode = 0;
char Temp;
void main(void)
{

	All_Init();
	Timer0Init();
	Temp = Get_Temp();
	while(1)
	{
		
		if(flag300ms)
		{
			flag300ms = 0;
			if(Start_Ds18B20())
			{
				Temp = Get_Temp();
			}
		}
		if(Max>=Min)
		{
			if(Temp<=Min)
			{
				 
				 tempMode = 0;			 
				 if(flag800ms)
				 {	
					Led_Illume(0xfe);
				 }else{
					Led_Illume(0xff);
				 }
			}
			if(Temp>Min && Temp<Max)
			{
				 
				 tempMode = 1;
				 if(flag400ms)
				{	 	
					Led_Illume(0xfe);

				 }else{
					Led_Illume(0xff);
				 }
			}
			if(Temp>=Max)
			{
				
				 tempMode = 2;
				 if(flag200ms)
				 {			
					Led_Illume(0xfe);
				 }else{
					Led_Illume(0xff);
				 }
			}
		}
		if((num[2]*10+num[3])>(num[0]*10+num[1]))
		{
			Led_Illume(0xfd);
		}
		show();
		Key_Scan();
		Key_Action();
	}
}



void Timer0() interrupt 1
{
	static u16 T0_count0, T0_count1,T0_count2,T0_count3;
	T0_count0++;
	T0_count1++;
	T0_count2++;
	T0_count3++;
	if(T0_count0 == 300)
	{
		T0_count0 = 0;
		flag300ms = 1;
	}
	if(T0_count1 == 400)
	{
		T0_count1 = 0;
		flag400ms = ~flag400ms;
	}
	if(T0_count2 == 200)
	{
		T0_count2 = 0;
		flag200ms = ~flag200ms;
	}
	if(T0_count3 == 800)
	{
		T0_count3 = 0;
		flag800ms = ~flag800ms;
	}
	Nixie_Scan();
	Nixie_Show();
	relay();
}